package com.example.mypotiota_si.Activity;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.ashokvarma.bottomnavigation.BottomNavigationBar;
import com.example.mypotiota_si.Adapter.ListViewAdapter_wm_cg;
import com.example.mypotiota_si.Adapter.ListViewAdapter_wm_dp;
import com.example.mypotiota_si.Datas.CanGuan;
import com.example.mypotiota_si.Datas.CanGuan_nr;
import com.example.mypotiota_si.Datas.Dianpu;
import com.example.mypotiota_si.Datas.Dianpu_nr;
import com.example.mypotiota_si.R;

import java.util.ArrayList;
import java.util.List;

public class WaiMaiActivity extends AppCompatActivity {
    private static final String TAG = "WaiMaiActivity";
    private ImageView wm_fh;
    LinearLayout wm_ss;
    RecyclerView wm_cg_recycler_view,wm_dp_recycler_view;
    ListViewAdapter_wm_cg wm_cg_adapter;
    ListViewAdapter_wm_dp wm_dp_adapter;
    ArrayList<CanGuan> canGuan;
    ArrayList<Dianpu> dianpu;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wai_mai);
        //隐藏标题栏
        ActionBar actionBar=getSupportActionBar();
        if (actionBar!=null){
            actionBar.hide();
        }
        //添加数据
        init_Datas();

        //找到控件
        wm_fh=findViewById(R.id.wm_fh);
        wm_ss=findViewById(R.id.wm_ss);
        wm_cg_recycler_view=findViewById(R.id.wm_cg_recycler_view);
        wm_dp_recycler_view=findViewById(R.id.wm_dp_recycler_view);

        //页面布局
        LinearLayoutManager layoutManager1=new LinearLayoutManager(this);
        layoutManager1.setOrientation(RecyclerView.VERTICAL);
        wm_cg_recycler_view.setLayoutManager(layoutManager1);
        wm_cg_adapter=new ListViewAdapter_wm_cg(canGuan,WaiMaiActivity.this);
        wm_cg_recycler_view.setAdapter(wm_cg_adapter);

        LinearLayoutManager layoutManager2=new LinearLayoutManager(this);
        layoutManager2.setOrientation(RecyclerView.VERTICAL);
        wm_dp_recycler_view.setLayoutManager(layoutManager2);
        wm_dp_adapter=new ListViewAdapter_wm_dp(dianpu,WaiMaiActivity.this);
        wm_dp_recycler_view.setAdapter(wm_dp_adapter);

        //点击事件
        init_dj();
    }
    //添加数据
    private void init_Datas() {
        //给餐馆添加数据
        canGuan=new ArrayList<>();
        for (int i = 0; i < CanGuan_nr.cg_name.length; i++) {
            CanGuan cg=new CanGuan();
            cg.cg_name=CanGuan_nr.cg_name[i];
            canGuan.add(cg);
        }
//        for (int i = 0; i < canGuan.size(); i++) {
//            Log.i(TAG,canGuan.get(i).cg_name);
//        }
        //给店铺添加数据
        dianpu=new ArrayList<>();
        for (int j = 0; j < Dianpu_nr.icon.length; j++) {
            Dianpu dp=new Dianpu();
            dp.dp_icon=Dianpu_nr.icon[j];
            dp.dp_name=Dianpu_nr.name[j];
            dp.dp_pf=Dianpu_nr.pf[j];
            dp.dp_ys=Dianpu_nr.ys[j];
            dp.dp_sj=Dianpu_nr.sj[j];
            dp.dp_qs=Dianpu_nr.qs[j];
            dianpu.add(dp);
        }
    }

    //点击事件
    private void init_dj() {
        //点击返回
        wm_fh.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(WaiMaiActivity.this,MainActivity.class);
                startActivity(intent);
            }
        });
        //点击搜索
        wm_ss.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(WaiMaiActivity.this,SouSuoActivity.class);
                startActivity(intent);
            }
        });
    }
}
